package com.education.user.service;


import com.education.user.mapper.SysMenuMapper;
import com.education.user.mapper.SysMenuRoleMapper;
import com.education.user.pojo.SysMenu;
import com.education.user.pojo.SysMenuBig;
import com.education.user.pojo.SysRoleMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysMenuService {

    @Autowired
    private SysMenuMapper menuMapper;
    @Autowired
    private SysMenuRoleMapper menuRoleMapper;

    //根据菜单id 集合查询菜单列表
    public List<SysMenu> selectMenuList(List<Integer> list) {
        return menuMapper.selectMenuFirstList(list);
    }

    //根据菜单id 集合查询菜单列表
    public List<SysMenu> selectMenuListTwo(List<Integer> list) {
        return menuMapper.selectMenuFirstListTwo(list);
    }

    //根据父级id查询下级菜单列表
    public List<SysMenu> selectSysMenuByPId(Integer parentId,Integer roleId) {
        return menuMapper.selectSysMenuByPId(parentId,roleId);
    }

    //根据父级id查询下级菜单列表
    public List<SysMenuBig> selectSysMenuByParentId(Integer parentId) {
        return menuMapper.selectSysMenuByParentId(parentId);
    }

    //根据父级id查询下级菜单列表
    public SysMenu selectSysMenuById(Integer id) {
        SysMenu menu = new SysMenu();
        menu.setMenuId(id);
        return menuMapper.selectOne(menu);
    }

    //根据角色id查询菜单列表
    public List<SysRoleMenu> selectSysMenuByRoleId(Integer roleId) {
        SysRoleMenu sysRoleMenu = new SysRoleMenu();
        sysRoleMenu.setRoleId(roleId);
        return menuRoleMapper.select(sysRoleMenu);
    }

    //往中间表添加数据
    public int insertSysMenuRole(SysRoleMenu roleMenu) {
        return menuRoleMapper.insert(roleMenu);
    }

    //删除中间表数据
    public int deleteMenuRole(Integer roleId){
        return menuRoleMapper.deleteByPrimaryKey(roleId);
    }

}
